package com.ruoyi.pv.service.impl;

import com.doudou.minio.Minio;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.pv.domain.PvHomeImage;
import com.ruoyi.pv.service.IPvHomeImageService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 主页图片Service业务层处理
 *
 * @author zzx
 * @date 2023-05-06
 */
@Service
@Slf4j
public class PvHomeImageServiceImpl implements IPvHomeImageService {

    @Autowired private Minio minio;

    /**
     * https://www.jy-medtechs.com/minio-api/postpartum/applet-homePage-image.png
     */
    private String IMAGE_NAME = "applet-homePage-image.png";


    @Override
    public PvHomeImage url() {
        return PvHomeImage.builder().url(minio.createUrl(IMAGE_NAME)).build();
    }

    @Override
    public boolean updatePvHomeImage(MultipartFile file) {
        try{
            minio.delete(IMAGE_NAME);
            minio.uploadFileUdName(file.getInputStream(),IMAGE_NAME, file.getSize());
        }catch (Exception e){
            log.error("",e);
            return false;
        }
        return true;
    }
}
